﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace VendingMachine
{
    public class ProductLoader
    {
        public Dictionary<Product, int> Products { get; private set; }

        public ProductLoader()
        {
            LoadProducts();
        }


        private void LoadProducts()
        {
            //Make dynamic, add products via App.config (MEF)? ConfigurationSection & Handler
            Products = new Dictionary<Product, int>() 
            {
                { new Product() {Name="KitKat",   Price=85, InventoryKeyNumber=1}, 10 },
                { new Product() {Name="Mars",     Price=90, InventoryKeyNumber=2}, 10 },
                { new Product() {Name="Sneakers", Price=95, InventoryKeyNumber=5}, 10 }
            };
        }


        public string DisplayProducts()
        {
            StringBuilder usageMessage = new StringBuilder();
            usageMessage.AppendLine("Please choose from our appetising Menu..." + Environment.NewLine);
            usageMessage.AppendLine("Key in product key number followed by 'Enter' key..." + Environment.NewLine);

            foreach (Product prod in Products.Keys)
            {
                usageMessage.AppendLine("-- Key (" + (prod.InventoryKeyNumber) + ") for " + prod.Name + "\t Price: " + prod.Price + "p,  [Stock:" + Products[prod] + "]");
            }

            return usageMessage.ToString();
        }
    }
}
